class People {
  name!: string;

  age!: number;

  constructor(name: string, age: number) {
    this.name = name;
    this.age = age;
  }
}

class Son extends People {}

// 获取构造函数的参数类型
type ConstructorParametersType<T extends new (...args: any[]) => any> = T extends new (
  ...args: infer P
) => any
  ? P
  : never;

type p = ConstructorParametersType<typeof People>;

interface Ref<T = any> {
  value: T;
}

function isRef(value: any): value is Ref {
  return !!value.value;
}

function unref<T>(ref: T): T extends Ref<infer E> ? E : T {
  return isRef(ref) ? ref.value : ref;
}

const a = unref({ value: 222 });

// 父子类型
type a1 = Extract<Son, People>; // 返回Son
type a2 = Extract<People, Son>; // 返回People

// 函数类型
type Func1 = (one: string, two: number) => string;
type Func2 = (one: string) => string;
type a3 = Extract<Func1, Func2>; // 返回never
type a4 = Extract<Func2, Func1>; // 返回Func2

// 约束T和U只能是传入对象类型
type CrossType<T> = Extract<T, object>;
// function cross<T, U>(obj1: Extract<T, object>, obj2: Extract<U, object>) {}
function cross<T, U>(obj1: CrossType<T>, obj2: CrossType<U>) {}
cross({}, {}); // 正确
// cross('', {}); // 错误string不能赋值给never类型

type Obj = {
  name: string;
  age: number;
  count: number;
};

// 去除name字段
type t = Exclude<keyof Obj, 'name'>;
const obj = {
  name: '',
  age: 222,
  cc: 11,
};
type aaa = typeof obj;

// 1 keyof 将一个对象类型的所有key取出并返回一个联合类型

// 2 typeof 用于取一个变量的类型
const num: number = 4;
const str: string = '';
type t1 = typeof num; // 返回number
type t2 = typeof str; // 返回string
type t3 = typeof obj; // 返回：{name: string; age: number; cc: number}
type ee = keyof any;

const aa: Object = {};
const aaa: object = 3;


export {};
type Record<T> = {
	[P in keyof any]: T;
}

type aa = Record<object>; // 返回类型{[k: string]: object}

type P = {
  name: string;
  age: number;
}

type pp = Pick<P, "name">;